from leetcode_test import TreeNode

class Solution:
    def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:

        def traverse(p , q):
            print(p, q)
            if not p and not q:
                return True
            if p.val != q.val:
                return False

            return traverse(p.left, q.left) and traverse(p.right, q.right)
        try:
            return traverse(p, q)
        except:
            return False

if __name__ == "__main__":
    p = TreeNode.create([1,2,3,4])
    q = TreeNode.create([1,2,3,4])
    print(Solution().isSameTree(p, q))
